package org.oos.dao.impl;

import static org.oos.ApiUrlProvider.Contacts;

import org.oos.atom.ContactFeed;
import org.oos.atom.entries.ContactEntry;
import org.oos.atom.entries.impl.ContactEntryImpl;
import org.oos.atom.impl.ContactFeedImpl;
import org.oos.dao.ContactDao;
import org.oos.dao.lists.impl.FullAccessDynamicList;

import com.google.api.client.http.GenericUrl;

public class ContactDaoImpl extends
		AbstractDao<ContactEntry, ContactFeed<ContactEntry>> implements
		ContactDao {
	
	private String userSlug;

	public ContactDaoImpl() {
		super(ContactFeedImpl.class, ContactEntryImpl.class);
	}

	@Override
	protected GenericUrl getEntryUrl(ContactEntry entry) {
		return getEntryUrl(entry.getSlug());
	}

	@Override
	protected GenericUrl getEntryUrl(String param) {
		if (userSlug != null) {
			return Contacts.getUrl(userSlug, param);
		} else {
			throw new IllegalStateException("There must be a slug");
		}
	}

	@Override
	protected GenericUrl getFeedUrl() {
		if (userSlug != null) {
			return Contacts.getUrl(userSlug);
		} else {
			throw new IllegalStateException("There must be a slug");
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	protected FullAccessDynamicList<ContactEntry, ContactFeed<ContactEntry>> getList(ContactFeed feed) {
		return new FullAccessDynamicList<ContactEntry, ContactFeed<ContactEntry>>(this, feed);
	}

	@Override
	public void setUserSlug(String userSlug) {
		this.userSlug = userSlug;
	}

}
